package org.yx.service.smat.view_product_manufacture_alternate_material;

import org.dbist.dml.Page;
import org.dbist.dml.Query;
import org.yx.utils.BaseService;

import com.xiaoleilu.hutool.util.StrUtil;

/**
 * 查询某BOM的替代料
 * @author zxw
 * @since 2018/04/15
**/
public class SmatViewProductManufactureAlternateMaterialService extends BaseService {
	public SmatViewProductManufactureAlternateMaterialOut viewProductManufactureAlternateMaterial(
			SmatViewProductManufactureAlternateMaterialIn in) throws Exception {
		SmatViewProductManufactureAlternateMaterialOut out = new SmatViewProductManufactureAlternateMaterialOut();

		if (!StrUtil.isBlank(in.getProdCode()) && !StrUtil.isBlank(in.getProdVer())) {
			Query query = new Query(in.getPageIndex(), in.getPageSize());
			query.addFilter("orgCode", in.getUserOrgCode());
			query.addFilter("prodCode", in.getProdCode());
			query.addFilter("prodVer", in.getProdVer());
			if (!StrUtil.isBlank(in.getMainMatCode())) {
				query.addFilter("mainMatCode", in.getMainMatCode());
			}
			if (!StrUtil.isBlank(in.getMainMatVer())) {
				query.addFilter("mainMatVer", in.getMainMatVer());
			}
			if (!StrUtil.isBlank(in.getMatCode())) {
				query.addFilter("matCode", in.getMatCode());
			}
			if (!StrUtil.isBlank(in.getMatVer())) {
				query.addFilter("matVer", in.getMatVer());
			}

			Page<AltBomMat> altPage = selectPageBySqlFilePath("select_alternate_material.sql", query, AltBomMat.class);
			out.setAltList(altPage.getList());
			out.setTotalSize(altPage.getTotalSize());
		}

		return out;
	}
}